cd /disk/agedisk3/medicare.work/poterba-DUA52260/jetson-dua52260/botox/synth/100pct/robustness/feout

use growthgroupspanel_feout.dta, clear
keep if group == 999 

merge 1:1 dt using synth_fit.dta

local treatment_period = mofd(mdy(6,5,2007))
disp `treatment_period'

** Produce difference in series
gen deterrence = fit1 - out if dt >= `treatment_period'


** Time discount the difference at 10% 
local r = 1.1^(1/12)

gen deterrence_disc = deterrence*1/(`r'^(dt-`treatment_period'))
replace deterrence_disc = . if dt-`treatment_period' >= 60
count if !mi(deterrence_disc)
assert(r(N)==60)

*** Compute total
log using deterrence_feout.log, replace
preserve
collapse (sum) deterrence_disc
qui summarize deterrence_disc
local deterrence = r(min)
disp `deterrence'
restore
log close 

*** Truncate graph at 5 years 
drop if dt  - `treatment_period' >= 60
summarize dt 
local minperiod = r(min)
local maxperiod = r(max)

*** Settlement: 8/31/10
local settlement = mofd(mdy(8,31,2010))

format dt %tm_Mon_YY
twoway (scatter pmt_amt dt, mcolor(gs5)) (line out fit1 dt, lwidth(thick thick) lcolor(navy maroon)), xline(`treatment_period', lcolor(maroon)) xline(`settlement', lcolor(black)) xscale(range(`minperiod' `maxperiod')) xlabel(504 528 552 `treatment_period' 588 612) legend(order(2 "Botox" 3 "Synthetic Control")) xtitle("Month") ytitle("$/Month") graphregion(color(white)) ylabel( 0 "$0" 1000000 "$1M"  2000000 "$2M"  3000000 "$3M")

graph save "BotoxOverlay_feout.gph", replace
